package com.lrs.java.j2se_self._example.countWords;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileWordsCount extends WordsCount {
	private FileReader fr = null;
	private BufferedReader br = null;
	private String file =null;
	
	public FileWordsCount(String file) {
		this.file = file;
	}
	
	protected String getText() {
		String sumWords = null;
		
		try {
			fr = new FileReader(file);
			br = new BufferedReader(fr);
			String str = null;
			while((str=br.readLine()) != null) {
				sumWords += str;
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if(br != null) {
					br.close();
					br = null;
				}
				if(fr != null) {
					fr.close();
					fr = null;
				}
			} catch(IOException e) {
				e.printStackTrace();
			}
		}
		return sumWords;
	}
	
}
